package lookas.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.validation.constraints.Size;

public class Customer implements Serializable {

    private static final long serialVersionUID = -5451613999575087242L;

    @Size(min = 2)
    private String            firstname;
    @Size(min = 2)
    private String            lastname;
    @Size(min = 11, max = 11)
    private String            pesel;

    private Set<Transaction>  transactions     = new HashSet<Transaction>();

    public Customer() {
    }

    public Customer(String firstname, String lastname, String pesel) {
        this.firstname = firstname;
        this.lastname = lastname;
        this.pesel = pesel;
    }

    public Set<Transaction> getTransactions() {
        return transactions;
    }

    public void setTransactions(Set<Transaction> transactions) {
        this.transactions = transactions;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getFirstname() {
        return firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public void setPesel(String pesel) {
        this.pesel = pesel;
    }

    public String getPesel() {
        return pesel;
    }

    @Override
    public int hashCode() {
        return this.getPesel() != null ? this.getPesel().hashCode() : 0;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        String o1 = this.getPesel();
        String o2 = other.getPesel();
        return (o1 == o2) || (o1 != null && o1.equals(o2));
    }

    @Override
    public String toString() {
        return firstname + " " + lastname + ", " + pesel;
    }
}
